#include "tests_pch.h"
#include <maths/func.h>

using namespace black;

SUITE( func )
{
	TEST( _abs )
	{
		// Int
		CHECK( 0 == black::abs( 0 ) );
		CHECK( 1 == black::abs( -1 ) );
		CHECK( 1 == black::abs( 1 ) );
		CHECK( 7777 == black::abs( -7777 ) );
		CHECK( 7777 == black::abs( 7777 ) );

		// Float
		CHECK( 0.f == black::abs( 0.f ) );
		CHECK( 1.f == black::abs( -1.f ) );
		CHECK( 1.f == black::abs( 1.f ) );
		CHECK( 7777.f == black::abs( -7777.f ) );
		CHECK( 7777.f == black::abs( 7777.f ) );
		CHECK( 1e8f == black::abs( -1e8f ) );
		CHECK( 1e8f == black::abs( 1e8f ) );

		// Double
		CHECK( 0. == black::abs( 0. ) );
		CHECK( 1. == black::abs( -1. ) );
		CHECK( 1. == black::abs( 1. ) );
		CHECK( 7777. == black::abs( -7777. ) );
		CHECK( 7777. == black::abs( 7777. ) );
		CHECK( 1e8 == black::abs( -1e8 ) );
		CHECK( 1e8 == black::abs( 1e8 ) );
	}

	TEST( toInt )
	{
		CHECK( 1254844 == black::toInt( 1254844.498444f ) );
		CHECK( 1 == black::toInt( 1.2f ) );
		CHECK( 1 == black::toInt( 1.7f ) );
		CHECK( 1 == black::toInt( 1.f ) );
		CHECK( 0 == black::toInt( 0.99999f ) );
		CHECK( 0 == black::toInt( 0.f ) );
		CHECK( -1 == black::toInt( -1.2f ) );
		CHECK( -1 == black::toInt( -1.7f ) );
		CHECK( -1 == black::toInt( -1.f ) );
		CHECK( 0 == black::toInt( -0.99999f ) );
		CHECK( -1254844 == black::toInt( -1254844.498444f ) );
	}

	TEST( roundToInt )
	{
		CHECK( 1254844 == black::roundToInt( 1254844.498444f ) );
		CHECK( 1 == black::roundToInt( 1.2f ) );
		CHECK( 2 == black::roundToInt( 1.7f ) );
		CHECK( 1 == black::roundToInt( 1.f ) );
		CHECK( 1 == black::roundToInt( 0.99999f ) );
		CHECK( 0 == black::roundToInt( 0.f ) );
		CHECK( -1 == black::roundToInt( -1.2f ) );
		CHECK( -2 == black::roundToInt( -1.7f ) );
		CHECK( -1 == black::roundToInt( -1.f ) );
		CHECK( -1 == black::roundToInt( -0.99999f ) );
		CHECK( -1254844 == black::roundToInt( -1254844.498444f ) );
	}

	TEST( toFloat )
	{
		CHECK( 7.f == black::toFloat( 7 ) );
		CHECK( -7.f == black::toFloat( -7 ) );
		CHECK( 0.f == black::toFloat( 0 ) );
	}

	TEST( _ceil )
	{
		CHECK( 2.f == black::ceil( 1.5f ) );
		CHECK( 1.f == black::ceil( 1.f ) );
		CHECK( 1.f != black::ceil( 1.5f ) );
		CHECK( -1.f == black::ceil( -1.5f ) );
	}

	TEST( _floor )
	{
		CHECK( 1.f == black::floor( 1.5f ) );
		CHECK( 1.f == black::floor( 1.f ) );
		CHECK( 2.f != black::floor( 1.5f ) );
		CHECK( -2.f == black::floor( -1.5f ) );
	}

	TEST( _round )
	{
		CHECK( 2.f == black::round( 1.5f ) );
		CHECK( 1.f == black::round( 1.f ) );
		CHECK( 2.f == black::round( 1.5f ) );
		CHECK( -2.f == black::round( -1.5f ) );
	}
}